package com.hae.shop.micoshopmemberservice.mapper;

import com.hae.shop.member.model.reqDto.UserRegistryReqDto;
import com.hae.shop.micoshopmemberservice.mapper.model.UserDo;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

public interface UserMapper {

    @Insert("INSERT INTO `mico_shop_user` VALUES (null,#{mobile}, #{email}, #{password}, #{userName}, null, null, now(), '1', null, #{qqOpenId}, #{wxOpenId}, now());")
    int register(UserDo userDo);

    @Select("SELECT * FROM mico_shop_user WHERE MOBILE=#{mobile};")
    UserRegistryReqDto existMobile(@Param("mobile") String mobile);

    @Select("SELECT USER_ID AS USERID FROM mico_shop_user  WHERE MOBILE=#{mobile} and password=#{password};")
    Long login(@Param("mobile") String mobile, @Param("password") String password);

    @Select("SELECT USER_ID AS USERID ,MOBILE AS MOBILE,EMAIL AS EMAIL,PASSWORD AS PASSWORD, USER_NAME AS USER_NAME,SEX AS SEX," +
            "AGE AS AGE, CREATE_TIME AS CREATETIME, UPDATE_TIME AS UPDATETIME, IS_AVALIBLE AS ISAVALIBLE, PIC_IMG AS PICIMG, QQ_OPENID AS QQOPENID," +
            "WX_OPENID AS WXOPENID FROM mico_shop_user WHERE user_Id=#{userId}")
    UserDo findByUserId(@Param("userId") Long userId);

    @Select("SELECT t.USER_ID FROM mico_shop_user t WHERE t.QQ_OPENID = #{qqid} OR t.WX_OPENID = #{qqid};")
    Long selectUserByQQId(String qqid);
}
